//
//  LGSError.m
//  LogicSim
//
//  Created by Jeremy Pereira on 04/04/2012.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "LGSError.h"

NSString* const LGS_METHOD_UNIMPLEMENTED = @"LGSMEthodUnimplenented";
NSString* const LGS_ERROR_DOMAIN = @"net.jeremyp.logicsim";

@interface  LGSError ()

-(id) initWithCode:(NSInteger)code userInfo:(NSDictionary *)dict;

@end

@implementation LGSError

-(id) initWithCode:(NSInteger)code userInfo:(NSDictionary *)dict
{
    return [self initWithDomain: LGS_ERROR_DOMAIN code: code userInfo: dict];
}

+(NSError*) deserialisationFailureReason: (NSString*) reason
{
    NSDictionary* userInfo 
    	= [NSDictionary dictionaryWithObjectsAndKeys: 
        	NSLocalizedString(@"Failed to create logic simulation objects", @""), 
           NSLocalizedDescriptionKey, 
           reason,
           NSLocalizedFailureReasonErrorKey,
           nil];
    
    return [[[self class] alloc] initWithCode: LGS_ERR_DESERIALISATION_FAILURE
                            	 userInfo: userInfo];
}

+(NSError*) invalidConnection: (NSString*) connectionString
{
    NSString* description = [NSString stringWithFormat:
                             	NSLocalizedString(@"Invalid connection: %@", @"error"),
                                                	connectionString];
    NSDictionary* userInfo
        = [NSDictionary dictionaryWithObjectsAndKeys:
            description, NSLocalizedDescriptionKey,
            nil];
    
    return [[[self class] alloc] initWithCode: LGS_ERR_DESERIALISATION_FAILURE
                                     userInfo: userInfo];
}

@end
